/*
字符有一字节和双字节编码，
00–7F范围内是一位，和ASCII保持一致，此范围内严格上说有96个文字和32个控制符号。
之后的双字节中，前一字节是双字节的第一位。
	第一字节的范围是81–FE（也就是不含80和FF），第
	二字节的一部分领域在40–FE，其他领域在80–FE。

具体来说，定义的是下列字节:
GBK的编码范围
范围			第1字节	第2字节		编码数	字数
水准 GBK/1	A1–A9	A1–FE		846		717
水准 GBK/2	B0–F7	A1–FE		6,768	6,763
水准 GBK/3	81–A0	40–FE (7F除外)	6,080	6,080
水准 GBK/4	AA–FE	40–A0 (7F除外)	8,160	8,160
水准 GBK/5	A8–A9	40–A0 (7F除外)	192	166
用户定义		AA–AF	A1–FE		564
用户定义		F8–FE	A1–FE		658
用户定义		A1–A7	40–A0 (7F除外)	672
合计:			23,940	21,886
*/

#include <cstdlib>
#include <iostream>
#include <fstream>
#include <assert.h>

using namespace std;

int main()
{
	const int buffersize=1024*1024*16;
	char* buffer = new char[buffersize];
	assert(NULL != buffer);

	//char* pos = buffer;
	
	ofstream fout("gbkCodeTable");
	// 单字节gbk字符
	int loopcount=0;
	for(unsigned char fchar=0x0; fchar<=0x7F; ++fchar)
	{
		//cout<<(char)fchar<<endl;
		if((char)fchar != '\n')
		{
			fout.put((char)fchar);
		}
		fout.put('\n');
		++ loopcount;
	}
	cout<<"1bye count:"<<loopcount<<endl;
	// 双字节gbk字符

	//水准 GBK/1	A1–A9	A1–FE		846		717
	loopcount=0;
	for(unsigned char fchar=0xA1; fchar<=0xA9; ++fchar)
	{
		for(unsigned char schar=0xA1; schar<=0xFE; ++schar)
		{
			fout.put((char)fchar);
			fout.put((char)schar);
			fout.put('\n');
			++ loopcount;
		}
	}
	cout<<"2bye (0xA1-0xA9,0xA1-0xFE) count:"<<loopcount<<endl;

	//水准 GBK/2	B0–F7	A1–FE		6,768	6,763
	loopcount=0;
	for(unsigned char fchar=0xB0; fchar<=0xF7; ++fchar)
	{
		for(unsigned char schar=0xA1; schar<=0xFE; ++schar)
		{
			fout.put((char)fchar);
			fout.put((char)schar);
			fout.put('\n');
			++ loopcount;
		}
	}
	cout<<"2bye (0xB0-0xF7,0xA1-0xFE) count:"<<loopcount<<endl;

	//水准 GBK/3	81–A0	40–FE (7F除外)	6,080	6,080
	loopcount=0;
	for(unsigned char fchar=0x81; fchar<=0xA0; ++fchar)
	{
		for(unsigned char schar=0x40; schar<=0xFE; ++schar)
		{
			if(0x7F == (char)schar)
			{
				continue;
			}
			fout.put((char)fchar);
			fout.put((char)schar);
			fout.put('\n');
			++ loopcount;
		}
	}
	cout<<"2bye (0x81-0xA0,0x40-0xFE) count:"<<loopcount<<endl;

	//水准 GBK/4	AA–FE	40–A0 (7F除外)	8,160	8,160
	loopcount=0;
	for(unsigned char fchar=0xAA; fchar<=0xFE; ++fchar)
	{
		for(unsigned char schar=0x40; schar<=0xA0; ++schar)
		{
			if(0x7F == (char)schar)
			{
				continue;
			}
			fout.put((char)fchar);
			fout.put((char)schar);
			fout.put('\n');
			++ loopcount;
		}
	}
	cout<<"2bye (0xAA-0xFE,0x40-0xA0) count:"<<loopcount<<endl;

	//水准 GBK/5	A8–A9	40–A0 (7F除外)	192	166
	loopcount=0;
	for(unsigned char fchar=0xA8; fchar<=0xA9; ++fchar)
	{
		for(unsigned char schar=0x40; schar<=0xA0; ++schar)
		{
			if(0x7F == (char)schar)
			{
				continue;
			}
			fout.put((char)fchar);
			fout.put((char)schar);
			fout.put('\n');
			++ loopcount;
		}
	}
	cout<<"2bye (0xA8-0xA9,0x40-0xA0) count:"<<loopcount<<endl;

	fout.close();
	delete buffer;
}
